
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link rel=stylesheet href='include/hoj.css' type='text/css'>
</head>
<body>
<center>
<div style="width:90%; text-align:left">
<img src="image/logo.png"/>
</div>
<table width=96%> 
	<tr align="center" class='hd' valign="top">
				<th><a href="faqs.php">F.A.Qs</a></th>
		<th><a href="./bbs.php">Web Board</a></th>
		<th><a href="./">Home</a></th>
		<th><a href="./problemset.html">ProblemSet</a></th>
		<th><a href="./status.php">Status</a></th>
		<th><a href="./ranklist.php">Ranklist</a></th>
		<th><a href="./contest.php">Contest</a></th>
		<th><a href=loginpage.php>Login</a></th><th><a href=registerpage.php>Register</a></th>	</tr>
</table>
</center>
<center>
<div class="notice">
	<div>
		<B>Notice:</B>鉴于种种原因，本OJ自下周星期一（3月5号）开始不再全面开放，请各位做好善后事宜，谢谢合作。	</div>
</div>
</center>
</div>
<title>Problem 2321. -- [BeiJing2011集训]星器 -- 衡阳八中OJ离线版-2012-02-29</title><center><h2>2321: [BeiJing2011集训]星器</h2><span class=green>Time Limit: </span>1 Sec&nbsp;&nbsp;<span class=green>Memory Limit: </span>128 MB<br><span class=green>Submit: </span>129&nbsp;&nbsp;<span class=green>Solved: </span>73<br>[<a href='submitpage.php?id=2321'>Submit</a>][<a href='problemstatus.php?id=2321'>Status</a>][<a href='bbs.php?id=2321'>Discuss</a>]</center><h2>Description</h2><div class=content><h2 style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-weight: normal; font-size: 12pt; font-style: italic; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></h2>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">Magic&nbsp;Land</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">上的时间又过了若干世纪&hellip;&hellip;</span><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">现在，人们谈论着一个传说：从前，他们的祖先来到了一个位于东方的岛屿，那里简直就是另外一个世界。善于分析与构造的</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">Magic&nbsp;Land</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">上的人们总是不明白那里的人们是如何不借助精确的实验与计算驱动和操纵魔法。</span><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">偶然地，一个魔法使（</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">Magician</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">）来到了</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">Magic&nbsp;Land</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">，在临走的时候留下了一个神奇的盒子，叫做</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">星器</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">（</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">Casket&nbsp;of&nbsp;star</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">）。</span><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">虽然不知道这个盒子是做什么的，但是经过了大量的实验和计算后，人们已经清楚它的一些事实：</span><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: left"><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">1<font face="宋体">．</font></span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">星器</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">之中有</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">N<font face="宋体">&times;</font><font face="Times New Roman">M</font></span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">个区域，可看作分成</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">行和</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">M</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">列的格子，每个区域之中有若干单位的称为&ldquo;星&rdquo;的对象，这个对象的最小单位已经被确定，所以，这个数量总是整数。</span><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: left"><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">2<font face="宋体">．魔法使可以驱动</font></span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">星器</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">中位于</span><span style="font-weight: bold; font-size: 12pt; font-family: '宋体'; text-decoration: underline; mso-spacerun: 'yes'">同一行或同一列</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">的</span><span style="font-weight: bold; font-size: 12pt; font-family: '宋体'; text-decoration: underline; mso-spacerun: 'yes'">不相邻</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">（有公共边的区域称为相邻的）两个区域中各<font face="Times New Roman">1</font><font face="宋体">单位的&ldquo;星&rdquo;，使得它们</font></span><span style="font-weight: bold; font-size: 12pt; font-family: '宋体'; text-decoration: underline; mso-spacerun: 'yes'">分别向中心移动<font face="Times New Roman">1</font><font face="宋体">格</font></span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">。</span><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: left"><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">3<font face="宋体">．每一次使用</font><font face="Times New Roman">2</font><font face="宋体">中的方法驱动&ldquo;星&rdquo;，将会产生魔力，魔法使会得到这一部分魔力。</font></span><span style="font-weight: bold; font-size: 12pt; font-family: '宋体'; text-decoration: underline; mso-spacerun: 'yes'">魔力的量等于这个两个区域之间所间隔的区域数</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">。</span><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: left"><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: left"><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">这样，我们可以用一个</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">N<font face="宋体">&times;</font><font face="Times New Roman">M</font></span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">的数表来表示</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">星器</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">的状态，比如</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">N=2</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">，</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">M=3</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">时：</span><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: left"><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p>
<table align="center" style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0pt; padding-top: 0pt; border-collapse: collapse; mso-table-layout-alt: fixed">
    <tbody>
        <tr style="height: 14.8pt">
            <td valign="top" width="48" style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: rgb(0,0,0) 0.5pt solid; padding-left: 5.4pt; padding-bottom: 0pt; border-left: rgb(0,0,0) 0.5pt solid; width: 36.7pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid; mso-border-bottom-alt: 0.5000pt solid rgb(0,0,0); mso-border-left-alt: 0.5000pt solid rgb(0,0,0); mso-border-right-alt: 0.5000pt solid rgb(0,0,0); mso-border-top-alt: 0.5000pt solid rgb(0,0,0)">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-weight: bold; font-size: 12pt; font-family: '宋体'; text-decoration: underline">2</span><span style="font-weight: bold; font-size: 12pt; font-family: 'Times New Roman'; text-decoration: underline"><o:p></o:p></span></p>
            </td>
            <td valign="top" width="48" style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: rgb(0,0,0) 0.5pt solid; padding-left: 5.4pt; padding-bottom: 0pt; border-left: medium none; width: 36.7pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid; mso-border-bottom-alt: 0.5000pt solid rgb(0,0,0); mso-border-left-alt: none; mso-border-right-alt: 0.5000pt solid rgb(0,0,0); mso-border-top-alt: 0.5000pt solid rgb(0,0,0)">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-size: 12pt; font-family: '宋体'">0</span><span style="font-size: 12pt; font-family: 'Times New Roman'"><o:p></o:p></span></p>
            </td>
            <td valign="top" width="48" style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: rgb(0,0,0) 0.5pt solid; padding-left: 5.4pt; padding-bottom: 0pt; border-left: medium none; width: 36.7pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid; mso-border-bottom-alt: 0.5000pt solid rgb(0,0,0); mso-border-left-alt: none; mso-border-right-alt: 0.5000pt solid rgb(0,0,0); mso-border-top-alt: 0.5000pt solid rgb(0,0,0)">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-weight: bold; font-size: 12pt; font-family: '宋体'; text-decoration: underline">1</span><span style="font-weight: bold; font-size: 12pt; font-family: 'Times New Roman'; text-decoration: underline"><o:p></o:p></span></p>
            </td>
            <td valign="top" width="48" style="border-right: rgb(255,255,255) 31.875pt; padding-right: 5.4pt; border-top: rgb(255,255,255) 31.875pt; padding-left: 5.4pt; padding-bottom: 0pt; border-left: medium none; width: 36.7pt; padding-top: 0pt; border-bottom: rgb(255,255,255) 31.875pt; mso-border-bottom-alt: 31.8750pt none rgb(255,255,255); mso-border-left-alt: none; mso-border-right-alt: 31.8750pt none rgb(255,255,255); mso-border-top-alt: 31.8750pt none rgb(255,255,255)">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-size: 12pt; font-family: 'Times New Roman'"><o:p></o:p></span></p>
            </td>
            <td valign="top" width="48" style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: rgb(255,255,255) 31.875pt; padding-left: 5.4pt; padding-bottom: 0pt; border-left: medium none; width: 36.7pt; padding-top: 0pt; border-bottom: rgb(255,255,255) 31.875pt; mso-border-bottom-alt: 31.8750pt none rgb(255,255,255); mso-border-left-alt: none; mso-border-right-alt: 0.5000pt solid rgb(0,0,0); mso-border-top-alt: 31.8750pt none rgb(255,255,255)">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-size: 12pt; font-family: 'Times New Roman'"><o:p></o:p></span></p>
            </td>
            <td valign="top" width="48" style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: rgb(0,0,0) 0.5pt solid; padding-left: 5.4pt; padding-bottom: 0pt; border-left: medium none; width: 36.7pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid; mso-border-bottom-alt: 0.5000pt solid rgb(0,0,0); mso-border-left-alt: none; mso-border-right-alt: 0.5000pt solid rgb(0,0,0); mso-border-top-alt: 0.5000pt solid rgb(0,0,0)">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-size: 12pt; font-family: '宋体'">1</span><span style="font-size: 12pt; font-family: 'Times New Roman'"><o:p></o:p></span></p>
            </td>
            <td valign="top" width="49" style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: rgb(0,0,0) 0.5pt solid; padding-left: 5.4pt; padding-bottom: 0pt; border-left: medium none; width: 36.75pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid; mso-border-bottom-alt: 0.5000pt solid rgb(0,0,0); mso-border-left-alt: none; mso-border-right-alt: 0.5000pt solid rgb(0,0,0); mso-border-top-alt: 0.5000pt solid rgb(0,0,0)">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-weight: bold; font-size: 12pt; font-family: '宋体'; text-decoration: underline">2</span><span style="font-weight: bold; font-size: 12pt; font-family: 'Times New Roman'; text-decoration: underline"><o:p></o:p></span></p>
            </td>
            <td valign="top" width="49" style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: rgb(0,0,0) 0.5pt solid; padding-left: 5.4pt; padding-bottom: 0pt; border-left: medium none; width: 36.75pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid; mso-border-bottom-alt: 0.5000pt solid rgb(0,0,0); mso-border-left-alt: none; mso-border-right-alt: 0.5000pt solid rgb(0,0,0); mso-border-top-alt: 0.5000pt solid rgb(0,0,0)">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-size: 12pt; font-family: '宋体'">0</span><span style="font-size: 12pt; font-family: 'Times New Roman'"><o:p></o:p></span></p>
            </td>
        </tr>
        <tr style="height: 16.15pt">
            <td valign="top" width="48" style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; padding-bottom: 0pt; border-left: rgb(0,0,0) 0.5pt solid; width: 36.7pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid; mso-border-bottom-alt: 0.5000pt solid rgb(0,0,0); mso-border-left-alt: 0.5000pt solid rgb(0,0,0); mso-border-right-alt: 0.5000pt solid rgb(0,0,0); mso-border-top-alt: 0.5000pt solid rgb(0,0,0)">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-size: 12pt; font-family: '宋体'">5</span><span style="font-size: 12pt; font-family: 'Times New Roman'"><o:p></o:p></span></p>
            </td>
            <td valign="top" width="48" style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; padding-bottom: 0pt; border-left: medium none; width: 36.7pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid; mso-border-bottom-alt: 0.5000pt solid rgb(0,0,0); mso-border-left-alt: none; mso-border-right-alt: 0.5000pt solid rgb(0,0,0); mso-border-top-alt: 0.5000pt solid rgb(0,0,0)">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-size: 12pt; font-family: '宋体'">1</span><span style="font-size: 12pt; font-family: 'Times New Roman'"><o:p></o:p></span></p>
            </td>
            <td valign="top" width="48" style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; padding-bottom: 0pt; border-left: medium none; width: 36.7pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid; mso-border-bottom-alt: 0.5000pt solid rgb(0,0,0); mso-border-left-alt: none; mso-border-right-alt: 0.5000pt solid rgb(0,0,0); mso-border-top-alt: 0.5000pt solid rgb(0,0,0)">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-size: 12pt; font-family: '宋体'">4</span><span style="font-size: 12pt; font-family: 'Times New Roman'"><o:p></o:p></span></p>
            </td>
            <td valign="top" width="48" style="border-right: rgb(255,255,255) 31.875pt; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; padding-bottom: 0pt; border-left: medium none; width: 36.7pt; padding-top: 0pt; border-bottom: rgb(255,255,255) 31.875pt; mso-border-bottom-alt: 31.8750pt none rgb(255,255,255); mso-border-left-alt: none; mso-border-right-alt: 31.8750pt none rgb(255,255,255); mso-border-top-alt: 31.8750pt none rgb(255,255,255)">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-size: 12pt; font-family: 'Times New Roman'"><o:p></o:p></span></p>
            </td>
            <td valign="top" width="48" style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; padding-bottom: 0pt; border-left: medium none; width: 36.7pt; padding-top: 0pt; border-bottom: rgb(255,255,255) 31.875pt; mso-border-bottom-alt: 31.8750pt none rgb(255,255,255); mso-border-left-alt: none; mso-border-right-alt: 0.5000pt solid rgb(0,0,0); mso-border-top-alt: 31.8750pt none rgb(255,255,255)">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-size: 12pt; font-family: 'Times New Roman'"><o:p></o:p></span></p>
            </td>
            <td valign="top" width="48" style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; padding-bottom: 0pt; border-left: medium none; width: 36.7pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid; mso-border-bottom-alt: 0.5000pt solid rgb(0,0,0); mso-border-left-alt: none; mso-border-right-alt: 0.5000pt solid rgb(0,0,0); mso-border-top-alt: 0.5000pt solid rgb(0,0,0)">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-size: 12pt; font-family: '宋体'">5</span><span style="font-size: 12pt; font-family: 'Times New Roman'"><o:p></o:p></span></p>
            </td>
            <td valign="top" width="49" style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; padding-bottom: 0pt; border-left: medium none; width: 36.75pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid; mso-border-bottom-alt: 0.5000pt solid rgb(0,0,0); mso-border-left-alt: none; mso-border-right-alt: 0.5000pt solid rgb(0,0,0); mso-border-top-alt: 0.5000pt solid rgb(0,0,0)">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-size: 12pt; font-family: '宋体'">1</span><span style="font-size: 12pt; font-family: 'Times New Roman'"><o:p></o:p></span></p>
            </td>
            <td valign="top" width="49" style="border-right: rgb(0,0,0) 0.5pt solid; padding-right: 5.4pt; border-top: medium none; padding-left: 5.4pt; padding-bottom: 0pt; border-left: medium none; width: 36.75pt; padding-top: 0pt; border-bottom: rgb(0,0,0) 0.5pt solid; mso-border-bottom-alt: 0.5000pt solid rgb(0,0,0); mso-border-left-alt: none; mso-border-right-alt: 0.5000pt solid rgb(0,0,0); mso-border-top-alt: 0.5000pt solid rgb(0,0,0)">
            <p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: center"><span style="font-size: 12pt; font-family: '宋体'">4</span><span style="font-size: 12pt; font-family: 'Times New Roman'"><o:p></o:p></span></p>
            </td>
        </tr>
    </tbody>
</table>
</p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: left"><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt; text-align: left"><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">当</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">星器</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">为左图的状态时，通过操纵第一行的第<font face="Times New Roman">1</font><font face="宋体">和</font><font face="Times New Roman">3</font><font face="宋体">个区域中的&ldquo;星&rdquo;（加粗的数字对应的区域），变为右图所示的状态，同时，将产生</font><font face="Times New Roman">1</font><font face="宋体">单位的魔力（因为这两个区域之间恰好隔了</font><font face="Times New Roman">1</font><font face="宋体">个区域）。</font></span><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-align: left"><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">在经过了进一步的研究之后，人们知道了这个</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">星器</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">最初的状态（</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">Ini</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">）以及最终被他们得到时的状态（</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">Fin</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">）。</span><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">你希望知道，</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">星器</span><span style="font-weight: bold; font-size: 12pt; font-family: '宋体'; text-decoration: underline; mso-spacerun: 'yes'">最多</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">帮助它的拥有者提供了多少的魔力。即：经过一系列上述操作由初态（</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">Ini</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">）变为终态（</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">Fin</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">），至多产生多少魔力。</span><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">需要注意的是，显然操作过程中每个区域内&ldquo;星&rdquo;的数量</span><span style="font-weight: bold; font-size: 12pt; font-family: '宋体'; text-decoration: underline; mso-spacerun: 'yes'">不能是负的</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">，即：如果那个区域已经没有&ldquo;星&rdquo;了，当然就不能继续操作了。</span><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<!--EndFragment--></div><h2>Input</h2><div class=content><p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">第一行</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">包含两个正</span><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">整数</span><span style="font-size: 12pt; font-style: italic; font-family: 'Times New Roman'; mso-spacerun: 'yes'">N</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">、</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">M</span><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">表示</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">星器</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">的大小</span><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">。</span><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'">接下来的</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">行，每行包含</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">M</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">个自然数：</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">Ini</span><span style="font-size: 12pt; vertical-align: sub; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">ij</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">，描绘了初态（</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">Ini</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">）。</span><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt; text-indent: 21pt"><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">在一个空行后的</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">N</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">行，每行包含</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">M</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">个自然数：</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">Fin</span><span style="font-size: 12pt; vertical-align: sub; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">ij</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">，描绘了终态（</span><span style="font-size: 12pt; font-style: italic; font-family: '宋体'; mso-spacerun: 'yes'">Fin</span><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">）。</span><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p></div><h2>Output</h2><div class=content><p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 12pt; font-family: '宋体'; mso-spacerun: 'yes'">输出一个正整数，表示至多产生的魔力。</span><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<h2 style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-size: 12pt; font-family: 'Times New Roman'; mso-spacerun: 'yes'"><o:p></o:p></span></h2></div><h2>Sample Input</h2>
			<div class=content><span class=sampledata>【输入样例1】<br />
5 5<br />
<br />
1 0 0 0 1<br />
<br />
0 0 0 0 0<br />
<br />
0 0 0 0 0<br />
<br />
0 1 0 1 1<br />
<br />
1 0 0 0 0<br />
<br />
<br />
0 0 0 0 0<br />
<br />
0 0 0 0 1<br />
<br />
2 0 0 0 1<br />
<br />
0 0 2 0 0<br />
<br />
0 0 0 0 0<br />
<br />
<br />
<br />
【输入样例2】<br />
1 4<br />
<br />
10 20 30 40<br />
<br />
<br />
0 0 100 0<br />
<br />
</span></div><h2>Sample Output</h2>
			<div class=content><span class=sampledata>【输出样例1】<br />
7<br />
<br />
【样例1解释】<br />
唯一的一种操作方法是：<br />
<br />
对第5列的两个“星”进行一次操作，产生魔力2；<br />
<br />
对第1列的两个“星”进行两次操作，产生魔力3+1；<br />
<br />
对第4行的两个“星”进行一次操作，产生魔力1；<br />
<br />
一共产生7单位的魔力。<br />
<br />
【输出样例2】<br />
50<br />
<br />
<br />
</span></div><h2>HINT</h2>
			<div class=content><p><p>【数据规模和约定】<br /><br />
40%的数据中N &le; 2，如样例2；</p><br />
<p>100%的数据中1 &le; N，M &le; 200，Iniij，Finij &le; 1000。</p><br />
<p>所有数据保证了至少存在一个操作方法使得星器由初态变为终态，同时保证了初态与终态不是完全相同的。</p><br />
<p></p></p></div><h2>Source</h2>
			<div class=content><p><a href='problemset.html?search='></a></p></div><center>[<a href='submitpage.php?id=2321'>Submit</a>][<a href='problemstatus.php?id=2321'>Status</a>][<a href='bbs.php?id=2321'>Discuss</a>]</center>﻿<br>

<a href="./"><span class=red>HOME</span></a>
<a href="javascript:history.go(-1)"><span class=red>Back</span></a>

<hr>
<center>
	<div class="footer">
			<a href=setlang.php?lang=ko>한국어</a>&nbsp;
		<a href=setlang.php?lang=cn>中文</a>&nbsp;
		<a href=setlang.php?lang=fa>فارسی</a>&nbsp;
		<a href=setlang.php?lang=en>English</a>&nbsp;
		<a href=setlang.php?lang=th>ไทย</a>
	<br>		<div>版权所有 &copy;2008-2012 WaterPark Organization. | <script src="http://s21.cnzz.com/stat.php?id=2982771&web_id=2982771" language="JavaScript"></script>
</div>
		<div>Based on opensource project <a href="http://hustoj.googlecode.com">hustoj</a>.</div>
	</div>
</center>
</body>
</html>
